package polymorphism;

public class Dog extends Animal {

    public void eat() {
        System.out.println("Dog的eat方法");
    }

    public void play() {
        System.out.println("Dog独有的play方法");
    }

    public static void main(String[] args) {
//        Animal animal = new Dog();
//        animal.eat();
//        //play引用在animal中不存在，将animal引用还原为Dog类引用
//        Dog dog = (Dog) animal;
//         dog.play();
        //此时animal引用和Dog毫无关系
//        Animal animal=new Animal();
//        //要发生向下转型首先父类引用就是通过该类向上转型产生的
//        Dog dog=(Dog) animal;
        Animal animal1=new Animal();
        Animal animal2=new Dog();
//        //此时animal1和Dog无关
//        System.out.println(animal1 instanceof Dog);
//        //此时animal2和Dog有关
//        System.out.println(animal2 instanceof Dog);
        if (animal1 instanceof Dog){
            Dog dog=(Dog) animal1;
            System.out.println("转型成功");
        }else{
            System.out.println("animal1不是Dog类型的引用");
        }
        if (animal2 instanceof Dog){
            Dog dog=(Dog) animal2;
            System.out.println("转型成功");
        }else{
            System.out.println("animal2不是Dog类型的引用");
        }
    }
}